package Com.javaserver.servlet;


import Com.javaserver.bean.departmentinquire;
import Com.javaserver.bean.train;
import Com.javaserver.dao.trainserver;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/trainadd")
public class traninaddServerlet extends HttpServlet {
    trainserver tra=new trainserver();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        train t=new train();
        t.setT_people(req.getParameter("name"));
        t.setT_theme(req.getParameter("theme"));
        t.setT_purpose(req.getParameter("purpose"));
        t.setT_time(req.getParameter("time"));
        t.setT_place(req.getParameter("place"));
        t.setT_participants(req.getParameter("partpi"));
        t.setT_remarks(req.getParameter("remarks"));

        if (tra.trainadd(t) == null) {
            req.getSession().setAttribute("msg", "添加失败");
            resp.sendRedirect(req.getContextPath() + "/AddTraining.jsp");
        } else {

            List<train> list = tra.tralist(1);
            req.getSession().setAttribute("tralist", list);
            req.getSession().setAttribute("msg", "添加成功");
            resp.sendRedirect(req.getContextPath() + "/tralist");
        }
    }


}
